﻿using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using RestSharp;

using DTFight;

public class UINetworkMgr : MonoBehaviour
{
	static public UINetworkMgr Instance = null;

	string url = "http://120.27.34.224:1337/";
	string localUrl = "http://127.0.0.1:1337/";
	public RestClient WebClient { get; set; }

	void Awake() {

		if (Instance == null)
		{
			Instance = this;
		
		//DontDestroyOnLoad(this);
		
			RoomMsg.Instance ().Init ();
			WebClient = new RestClient(localUrl);
		}
	}
	
	void OnDestroy()
	{
		if (Instance == this)
		{
			RoomMsg.Instance ().Destroy ();
			Instance = null;

			NetworkDispatcher.Instance.DisconnectGameServer();
		}
	}

	// Use this for initialization
	void Start ()
	{
		ConnectServer ();
	}

	// Update is called once per frame
	void Update ()
	{
		NetworkDispatcher.Instance.Update ();
	}

	void ConnectServer()
	{
		NetworkDispatcher.Instance.OnConnectGameServerConfirm += OnConnectServer;
		NetworkDispatcher.Instance.ConnectGameServer ("127.0.0.1", 50010);
		//NetworkDispatcher.Instance.ConnectGameServer ("120.27.34.224", 50000);
	}
	
	void OnConnectServer(int hChannel, bool first)
	{
		//UILoading.Instance.LoadScene("RoomList");
	}
}

